//
//  SinaBaseNavigationController.swift
//  SinaWeibo(Swift)
//
//  Created by 王忠迪 on 9/22/16.
//  Copyright © 2016 王忠迪. All rights reserved.
//

import UIKit

class SinaBaseNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

//        setBarButtonItem()
    }
    
    //mark:预留方法
    func setBarButtonItem() {
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(pop))
    }
    
    // MARK : 为什么一定要从push方法中才能设置呢,有没有别的方法能拿到leftBarButtonItem???
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if (self.childViewControllers.count > 0) {
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(pop))
            
            //注意:这里是viewController.hidesBottomBarWhenPushed
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    func pop() {
        self.popViewController(animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    

}
